package com.benzhitech.config;

import java.util.Map;

/**
 * 存储从 application.yaml 加载的配置信息。
 */
public class AppConfig {

    private Map<String, Object> server;
    private Map<String, Object> custom;

    // Getters and Setters

    public Map<String, Object> getServer() {
        return server;
    }

    public void setServer(Map<String, Object> server) {
        this.server = server;
    }

    public Map<String, Object> getCustom() {
        return custom;
    }

    public void setCustom(Map<String, Object> custom) {
        this.custom = custom;
    }

    // Helper methods to get specific values safely

    public int getHttpPort() {
        if (server != null && server.containsKey("http")) {
            Map<String, Object> httpConfig = (Map<String, Object>) server.get("http");
            if (httpConfig != null && httpConfig.containsKey("port")) {
                return (Integer) httpConfig.get("port");
            }
        }
        // 返回默认值或抛出异常
        return 8080; // Default HTTP port
    }

    public int getTcpPort() {
        if (server != null && server.containsKey("tcp")) {
            Map<String, Object> tcpConfig = (Map<String, Object>) server.get("tcp");
            if (tcpConfig != null && tcpConfig.containsKey("port")) {
                return (Integer) tcpConfig.get("port");
            }
        }
        // 返回默认值或抛出异常
        return 9090; // Default TCP port
    }

    public Object getCustomConfig(String key) {
        if (custom != null) {
            return custom.get(key);
        }
        return null;
    }

    // 可以根据需要添加更多获取具体配置项的方法
} 